package com.morehair.controller.admin;

import com.morehair.bean.bo.admin.CategoryBo;
import com.morehair.bean.bo.admin.RefundBo;
import com.morehair.bean.bo.admin.ShipBo;
import com.morehair.bean.pojo.Brand;
import com.morehair.bean.pojo.Category;
import com.morehair.bean.pojo.Issue;
import com.morehair.bean.pojo.KeyWord;
import com.morehair.bean.vo.admin.*;
import com.morehair.service.admin.ShopManageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author raohui
 * @Date 2021/6/4 23:30
 */
@RestController
@RequestMapping("admin")
public class ShopManageController {

    @Autowired
    ShopManageService shopManageService;

    //行政区域
    @RequestMapping("region/list")
    @RequiresPermissions("admin:region:list")
    public BaseRespVo regionList() {
        List<RegionDataVo> regionDataVos=shopManageService.selectRegion();
        return BaseRespVo.ok(regionDataVos);
    }

    //品牌制造商
    @RequestMapping("brand/list")
    @RequiresPermissions("admin:brand:list")
    public BaseRespVo brandList(Integer page,Integer limit, Integer id,String name,String sort,String order) {
        BrandDataVo brandDataVo= shopManageService.selectBrandList(page,limit,id,name,sort,order);
        return BaseRespVo.ok(brandDataVo);
    }

    //删除品牌信息
    @PostMapping("brand/delete")
    @RequiresPermissions("admin:brand:delete")
    public  BaseRespVo deleteBrand(@RequestBody Brand brand) {
        int i =shopManageService.deleteBrand(brand);
        if (i != 0) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }

    //更新品牌信息
    @PostMapping("brand/update")
    @RequiresPermissions("admin:brand:update")
    public  BaseRespVo updateBrand(@RequestBody Brand brand) {
        shopManageService.updateBrand(brand);
        return BaseRespVo.ok();
    }

    //新增品牌信息
    @PostMapping("brand/create")
    @RequiresPermissions("admin:brand:create")
    public  BaseRespVo createBrand(@RequestBody Brand brand) {
        shopManageService.createBrand(brand);
        return BaseRespVo.ok();
    }

    //品牌图片上传
    //TODO
    //@PostMapping("storage/create")
//    public  BaseRespVo pictureCreate() {
//
//        shopManageService.pictureCreate(brand);
//        return BaseRespVo.ok();
//    }


    //商品类目
    @RequestMapping("category/list")
    @RequiresPermissions("admin:category:list")
    public BaseRespVo categoryList() {
        List<CategoryDataVo> categoryDataVoList=shopManageService.selectCategoryList();
        return  BaseRespVo.ok(categoryDataVoList);
    }
    @RequestMapping("category/l1")
    @RequiresPermissions("admin:category:l1")
    public BaseRespVo categoryL1() {
        List<CategoryDataVo2> categoryDataVo2s=shopManageService.selectCategoryL1();
        return  BaseRespVo.ok(categoryDataVo2s);
    }

    //编辑商品类目
    @RequestMapping("category/update")
    @RequiresPermissions("admin:category:update")
    public BaseRespVo updateCategory(@RequestBody Category category) {
       shopManageService.updateCategory(category);
        return  BaseRespVo.ok();
    }

    //新增商品类目
    @RequestMapping("category/create")
    @RequiresPermissions("admin:category:create")
    public BaseRespVo createCategory(@RequestBody Category category) {
        shopManageService.createCategory(category);
        return  BaseRespVo.ok();
    }


    //删除商品类目
    @PostMapping("category/delete")
    @RequiresPermissions("admin:category:delete")
    public  BaseRespVo deleteLevelLCategory(@RequestBody CategoryBo categoryBo) {
        shopManageService.deleteLevelLCategory(categoryBo);
        return BaseRespVo.ok();
    }

    //商品类目图片上传
    // TODO


    //订单管理
    @RequestMapping("order/list")
    @RequiresPermissions("admin:order:list")
    public BaseRespVo orderList(Integer page, Integer limit, Integer orderStatusArray,String sort,String order,String  orderSn,Integer userId) {
        OrderDataVo orderDataVo=shopManageService.selectOrderList( page,  limit,  orderStatusArray, sort, order, orderSn, userId);
        return  BaseRespVo.ok(orderDataVo);
    }

    //订单详情
    @RequestMapping("order/detail")
    @RequiresPermissions("admin:order:detail")
    public  BaseRespVo orderDetail(Integer id) {
        OrderDetailDataVo orderDetailDataVo=shopManageService.selectOrderDetail(id);
        return BaseRespVo.ok(orderDetailDataVo);
    }

    //订单退款
    @RequestMapping("order/refund")
    @RequiresPermissions("admin:order:refund")
    public  BaseRespVo refundOrder(@RequestBody RefundBo refundBo) {
         shopManageService.refundOrder(refundBo);
        return BaseRespVo.ok("退款成功");
    }

    //订单商品发货
    @RequestMapping("order/ship")
    @RequiresPermissions("admin:order:ship")
    public  BaseRespVo shipOrder(@RequestBody ShipBo shipBo) {
        shopManageService.shipOrder(shipBo);
        return BaseRespVo.ok("发货成功");
    }

    //通用问题
    @RequestMapping("issue/list")
    @RequiresPermissions("admin:issue:list")
    public BaseRespVo issueList(Integer page,Integer limit,String question,String sort, String order) {
        IssueDataVo issueDataVo=shopManageService.selectIssueList( page, limit, question, sort,  order);
        return BaseRespVo.ok(issueDataVo);
    }

    //删除问题
    @PostMapping("issue/delete")
    @RequiresPermissions("admin:issue:delete")
    public BaseRespVo deleteIssue(@RequestBody Issue issue) {
        shopManageService.deleteIssue(issue);
        return BaseRespVo.ok("成功");
    }

    //更新问题
    @PostMapping("issue/update")
    @RequiresPermissions("admin:issue:update")
    public BaseRespVo updateIssue(@RequestBody Issue issue) {
        Issue issue1=shopManageService.updateIssue(issue);
        return BaseRespVo.ok(issue1);
    }

    //新增问题
    @PostMapping("issue/create")
    @RequiresPermissions("admin:issue:create")
    public BaseRespVo createIssue(@RequestBody Issue issue) {
        Issue issue1=shopManageService.createIssue(issue);
        return BaseRespVo.ok(issue1);
    }


    //关键词
    @RequestMapping("keyword/list")
    @RequiresPermissions("admin:keyword:list")
    public BaseRespVo keywordList(Integer page,Integer limit,String url,String keyword,String sort, String order) {
        KeyWordDataVo keyWordDataVo=shopManageService.selectKeywordList( page, limit, url, keyword, sort,  order);
        return BaseRespVo.ok(keyWordDataVo);
    }

    //删除关键词
    @RequestMapping("keyword/delete")
    @RequiresPermissions("admin:keyword:delete")
    public BaseRespVo deleteKeyword(@RequestBody KeyWord keyWord) {
        shopManageService.deleteKeyWord(keyWord);
        return BaseRespVo.ok("成功");
    }

    //更新关键词
    @RequestMapping("keyword/update")
    @RequiresPermissions("admin:keyword:update")
    public BaseRespVo updateKeyword(@RequestBody KeyWord keyWord) {
        KeyWord keyWord1=shopManageService.updateKeyWord(keyWord);
        return BaseRespVo.ok(keyWord1);
    }

    //新增关键词
    @RequestMapping("keyword/create")
    @RequiresPermissions("admin:keyword:create")
    public BaseRespVo createKeyword(@RequestBody KeyWord keyWord) {
        KeyWord keyWord1=shopManageService.createKeyWord(keyWord);
        return BaseRespVo.ok(keyWord1);
    }
}
